<?php

if(!isset($_GET['v']))
{
echo'<div class="col-md-9">';

	if(isset($_POST['op']) AND $_POST['op']=="sendmsg")
	{
	
		inboxsend($db, $_POST['senderID'], $_POST['recipientID'], $_POST['body'], $_POST['subject']);
		echo' <h2>Your inbox</h2><div class="alert alert-success"><span> Your message was successfully sent</span></div>';
	}
	if (isset($_POST['op']) AND $_POST['op']=="pimsearch" ) // The User is trying to send a new inbox. He's looking for a member
	{
		echo' <h2>Search user</h2>';
		searchuser($db, $_POST['user'], 'firstname');
		searchuser($db, $_POST['user'], 'surname');
			
	}
	
	if(isset($_GET['op']) AND $_GET['op']=='sendPIM' AND isset($_GET['user']))
	{
		$recipient=new User($db, $_GET['user']);
		echo' <h2>Send a new PIM</h2>
		<div style="width:100%"><form action="account.php?page=inbox" method="post">
			<label> Recipient
			<input type="text" value="'.$recipient->firstname . " " . $recipient->surname .'"/>
			</label><br/>
			<label>Subject
			<input type="text" name="subject" value="(none)"/><br/></label><br/>
			<label> Message 
			<textarea style="min-width: 350px;" name="body"></textarea></label><br/>
			<input type="hidden" name="op" value="sendmsg"/>
			<input type="hidden" value="'.$user->id.'" name="senderID"/>
			<input type="hidden" value="'.$recipient->id.'" name="recipientID"/>
			<br/> <input class="btn btn-primary" value="Send PIM" type="submit" style="width:200px;"/></form></div>';
	}
	if(!isset($_GET['op']) AND !isset($_POST['op']))//User just trying to display his inbox
	{

					echo'
					 <h2>Your inbox</h2>
		<ul id="myTab" class="nav nav-tabs">
        	<li class="active"><a href="#received" data-toggle="tab">Received</a></li>
        	<li><a href="#sent" data-toggle="tab">Sent</a></li>
			<li><a href="#newpim" data-toggle="tab">New PIM</a></li>
         </ul>
      	
		<div id="myTabContent" class="tab-content">
        <div class="tab-pane fade in active" id="received">
          ';				echo displayinbox($db, $user,"received");
		  echo'
        </div>

        <div class="tab-pane fade" id="sent">
         ';				echo displayinbox($db, $user,"sent");
		  echo'
        </div>
	
	<div class="tab-pane fade" id="newpim">
        				
						<form method="post" action="account.php?page=inbox">
						<label>Search user
						<input type="text" name="user" placeholder="(Type Firstname or surname)"  /></label>
						<input type="hidden" name="op" value="pimsearch" /><br/>
						<input type="submit" value="Search" class="btn btn-primary" style="width: 150px;"/>
						</form>
		  
        </div>
	</div>';
		
	}

	echo'
		</div>
			
		</div>
			</div>
				</div>
					</div>
						<div class="pad45 hidden-md hidden-lg"></div>
					<!--//page-->
	';
}

	
if(isset($_GET['v']) AND !empty($_GET['v']))
{
	echo'
		<div class="col-md-9">
		<h2>Message from '; echo getName($db, $user, $_GET['v']); echo'</h2>
				';
				displayconversation($db, $user, $_GET['v']);
					
				echo'
			
		</div>
			</div>
				</div>
					</div>
						<div class="pad45 hidden-md hidden-lg"></div>
					<!--//page-->
	
	';
	
	}
	
?>